#!/bin/bash


#
# 检测Linux中的命令是否存在
# https://segmentfault.com/q/1010000000156870
# https://www.cnblogs.com/embedded-linux/p/6206064.html
# https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
# https://www.cnblogs.com/tuzkee/p/3755230.html
# https://www.jianshu.com/p/da2add9d1328
#
#

if which brew 2>/dev/null; then
  echo "brew exists!"
else
  echo "nope, no brew installed."
fi

echo ""

which envsubst > /dev/null 2>&1
if [ $? == 0 ]; then
    echo "exist"
else
    echo "dose not exist"
    # apk add gettext
fi

echo ""



if hash envsubst  2>/dev/null; then
    echo 'brew exist'
else
    echo 'brew does not exist'
fi

echo ""


if hash envsubst  2>/dev/null; then echo 'brew exist';else echo 'brew does not exist' ;fi
# if hash envsubst  2>/dev/null; then echo 'brew exist'; apk del gettext ;else echo 'brew does not exist' ;apk add gettext ;fi

echo ""


# 不可靠
if command -v envsubst  2>/dev/null; then
    echo 'envsubst exist'
else
    echo 'envsubst does not exist'
fi

echo ""

# 不可靠
if command -v envsubst  2>/dev/null; then echo 'brew exist';else echo 'brew does not exist' ;fi
# if command -v envsubst  2>/dev/null; then echo 'brew exist'; apk del gettext ;else echo 'brew does not exist' ;apk add gettext ;fi


# 不可靠
command -v envsubst > /dev/null 2>&1
if [ $? == 0 ]; then
    echo "exist envsubst"
else
    echo "dose not exist envsubst"
fi

echo ""

# 不可靠
command -v envsubs > /dev/null 2>&1
if [ $? == 0 ]; then              
    echo "exist envsubs"         
else                              
    echo "dose not exist envsubs"
fi


echo ""                                  
                                         
if type  envsubst  2>/dev/null; then
    echo 'type envsubst exist'                
else                                     
    echo 'type envsubst does not exist'       
fi                                       
                                         
echo ""                                  
                                         
                                         
type  envsubst > /dev/null 2>&1     
if [ $? == 0 ]; then                     
    echo "exist type envsubst"                
else                                     
    echo "dose not exist type envsubst"       
fi                                       


#
# 不可靠
# if ! command -v <the_command> &> /dev/null
# then
#     echo "<the_command> could not be found"
#     exit
# fi
#
#


#
# 可靠
# if ! [ -x "$(command -v git)" ]; then
#   echo 'Error: git is not installed.' >&2
#   exit 1
# fi
#
# if ! [ -x "$(command -v envsubst)" ]; then echo 'not found'; else echo "found"; fi
#


#
# command_exists () {
#     type "$1" &> /dev/null ;
# }
# if command_exists mvim ; then
#     export VISUAL="mvim --nofork"
# fi
#

#
# exists()
# {
#   command -v "$1" >/dev/null 2>&1
# }
# if exists bash; then
#   echo 'Bash exists!'
# else
#   echo 'Your system does not have Bash'
# fi
#

#
# if foo --version >/dev/null 2>&1; then
#     echo Found
# else
#     echo Not found
# fi
#


if envsubst --version >/dev/null 2>&1; then echo Found; else echo Not found; fi
# if envsubst --version >/dev/null 2>&1; then echo Found;apk del gettext ; else echo Not found;apk add gettext ; fi










